package com.epro.dx.activity.forgetpassword;

import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.Html;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import com.epro.dx.R;
import com.epro.dx.activity.BaseFragmentActivity;
//import com.epro.dx.util.TextJustification;
import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Tracker;
import com.weipu.common.DXApplication;
import com.weipu.common.DXApplication.TrackerName;

public class ForgetPasswordSuccessActivity extends BaseFragmentActivity {
	private String emailUrl; 
	private String email;
	private int width;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		Tracker tracker = DXApplication.getContext().getTracker(TrackerName.APP_TRACKER);
		tracker.setScreenName(ForgetPasswordSuccessActivity.class.getSimpleName());
		tracker.send(new HitBuilders.ScreenViewBuilder().build());
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_forget_pwd_success);
		setLeftBtnContent(true, -1);
		Intent intent=getIntent();
		emailUrl=intent.getStringExtra("emailUrl");
		email=intent.getStringExtra("email");
		setTitleContent(R.string.forget_password_title);
		TextView emailTv=(TextView) findViewById(R.id.forget_pwd_suc);
		String first=getString(R.string.forget_password_success_first);
		String last=getString(R.string.forget_password_success_last);
		Display display = getWindowManager().getDefaultDisplay();           
		DisplayMetrics dm = new DisplayMetrics();           
		display.getMetrics(dm);           
		width = dm.widthPixels;                       
		//根据屏幕调整文字大小
		//emailTv.setLineSpacing(0f, 1.5f);
		//emailTv.setTextSize(8*(float)width/320f);                       
		//设置TextView
		emailTv.setText(Html.fromHtml(first+" " + "<font color='#fd8917'>" + email + "</font>" +" "+ last));         
		//TextJustification.justify(emailTv,emailTv.getWidth());
		Button button=(Button) findViewById(R.id.forget_pwd_check_in_now);
		button.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				try
                {
                    Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.android.vending");
                    if (null == launchIntent)
                    {
                        startActivity(new Intent(Intent.ACTION_VIEW,
                            Uri.parse(emailUrl)));
                    }
                    else
                    {
                        ComponentName comp =
                            new ComponentName("com.android.vending",
                                "com.google.android.finsky.activities.LaunchUrlHandlerActivity");
                        launchIntent.setComponent(comp);
                        launchIntent.setData(Uri.parse("market://details?id=" + getPackageName()));
                        startActivity(launchIntent);
                    }
                }
                catch (android.content.ActivityNotFoundException anfe)
                {
                    startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse(emailUrl)));
                }
				
			}
		});
	}
	
	
}
